<?php

namespace app\data\controller\api;

use think\admin\Controller;
use think\cache\driver\Redis;
use think\facade\Log;

/**
 * 基础数据接口
 * Class Data
 * @package app\data\controller\api
 */
class Data extends Controller
{
    /**
     * 获取轮播图片数据
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getSlider()
    {
        $data = sysdata(input('keys', 'slider'));
        $this->success('获取轮播图片数据', $data);
    }

    /**
     * 获取系统通知数据
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getNotify()
    {
        $query = $this->_query('DataUserNotify')->where(['status' => 1, 'deleted' => 0]);
        $result = $query->equal('id')->order('sort desc,id desc')->page(true, false, false, 20);
        $this->success('获取系统通知数据', $result);
    }

    public function getSmsReport(){
        $info = input("param.");
        $redis = new Redis();
        if($info) {
            $redis->set("SmsReport", $info);
        }else{
            dump($redis->get("SmsReport"));
        }
        Log::error(json_encode($info, 256));
        return json(['code'=>0, 'msg'=>'接收成功']);
    }

    public function test(){
        $ids = $this->app->db->name("jcg_devices")->where("online",1)->column("device_id");
        $redis = new Redis();
        dump(count($ids));
        foreach ($ids as $device_id){
            dump($redis->get($device_id));
            if(!$redis->get($device_id)){
                dump(http_post("https://jcgbackground.haoda365.cn/devices/api.index/getBoxSocket", ['device_id'=>$device_id]));
                dump($device_id);
            }
        }
    }
}